<?php
Class Manager_Model_sectionsolution extends Zend_Db_Table
{	
	protected $_name ="sections_solution";
	protected $_primary ="id";
	
	public function list_section()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'sections'));		          
        $results = $db->fetchAll($select);
        return $results;
	}
	public function sec_id()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'section'),array('title','id'));		          
        $results = $db->fetchAll($select);
        return $results;
	}
	public function listsec()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'section'),array('id','title'));		          
        $results = $db->fetchPairs($select);
        return $results;
	}
	public function searchkq($keyword,$status=-1)
	{
		$db = Zend_Registry::get('connectDb');
			$query="SELECT c . *,l.title as ngonngu
                  	FROM sections_solution AS c INNER JOIN language as l ON c.language_id=l.id 
					WHERE ((c.published=$status or $status=-1) AND (c.title like '%$keyword%'))						
					ORDER BY c.order desc";
			$result = $db->fetchAll($query)	;
		return $result;	
	}
	public function delete_muti($arrParam = null)
	{
	$tblGroup = new Manager_Model_sectionsolution();
		if(count($arrParam['cid'])>0)
	 	{
			$ids = implode(',', $arrParam['cid']);
			$where = 'id IN (' . $ids . ')'; 
			$tblGroup->delete($where); 
			 
	 	}
	}
    public function delete_data($id)
	{
		  	$tblGroup = new Manager_Model_sectionsolution();
			$where = "id =$id";
		    $tblGroup->delete($where);  	
	}
    public function getrow($id)
	{
				$db = Zend_Registry::get('connectDb');
				$query="Select * from sections_solution  where id=$id";
				$result = $db->fetchAll($query);
				return $result;
	}
	public function edit($data)
	{
		$tblGroup = new Manager_Model_category();
		$where ='id ='.$data['id'];
    	$data1  = array('title'=>$data['title'],'published'=>$data['published'],
    	               'order'=>$data['order'],'sec_id'=>$data['sec_id']);
    	$tblGroup->update($data1,$where);
	}
    public  function listItemabout($status)
	{
		   $db = Zend_Registry::get('connectDb');
			$query="SELECT s . *,l.title as ngonngu
                  	FROM sections_solution AS s INNER JOIN language as l ON s.language_id=l.id 
					WHERE (s.published=$status or $status=-1)
					ORDER BY s.id desc";
			$result = $db->fetchAll($query)	;
			return $result;	
	}
    public function save($data)
	{	
	$introtext = stripslashes($data['introtext']);
	
    if ($data['key']=='add')
		  {	
			$db        = Zend_Registry::get('connectDb');
			
		  	$data1 = array(
		  	                'title'         	=> $data['title'],
		                	'introtext'	        => $introtext,
		  	                'images'         	=> $data['images'],
		  	                'published'			=> $data['published'],
							'order'	            => $data['order'],
	                        'created'	        => date('Y-m-d h-i-s'),
		  	                'language_id'       => $data['language_id'],
		  			 );
	        $db->insert('sections_solution', $data1);
		  }
	else 
		  {
		  $tbl_section   = new Manager_Model_sectionsolution();
		  $where         = 'id ='.$data['id'];
    	  
		  $data1 = array(
		  	                'title'         	=> $data['title'],
		                	'introtext'	        => $introtext,
		  	                'images'         	=> $data['images'],
		  	                'published'			=> $data['published'],
							'order'	            => $data['order'],
	                        'created'	        => date('Y-m-d h-i-s'),
		  	                'language_id'       => $data['language_id'],
		  			 );
		  
    	  $tbl_section->update($data1,$where);
		  
		  }  
     }
     	
}